.class public Lcom/noshufou/android/su/widget/BetterPopupWindow;
.super Ljava/lang/Object;
.source "BetterPopupWindow.java"


# instance fields
.field protected final anchor:Landroid/view/View;

.field private background:Landroid/graphics/drawable/Drawable;

.field private root:Landroid/view/View;

.field private final window:Landroid/widget/PopupWindow;

.field private final windowManager:Landroid/view/WindowManager;


# direct methods
.method public constructor <init>(Landroid/view/View;)V
    .locals 2
    .parameter "anchor"

    .prologue
    .line 37
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 28
    const/4 v0, 0x0

    iput-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->background:Landroid/graphics/drawable/Drawable;

    .line 38
    iput-object p1, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->anchor:Landroid/view/View;

    .line 39
    new-instance v0, Landroid/widget/PopupWindow;

    invoke-virtual {p1}, Landroid/view/View;->getContext()Landroid/content/Context;

    move-result-object v1

    invoke-direct {v0, v1}, Landroid/widget/PopupWindow;-><init>(Landroid/content/Context;)V

    iput-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    .line 43
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    new-instance v1, Lcom/noshufou/android/su/widget/BetterPopupWindow$1;

    invoke-direct {v1, p0}, Lcom/noshufou/android/su/widget/BetterPopupWindow$1;-><init>(Lcom/noshufou/android/su/widget/BetterPopupWindow;)V

    invoke-virtual {v0, v1}, Landroid/widget/PopupWindow;->setTouchInterceptor(Landroid/view/View$OnTouchListener;)V

    .line 54
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->anchor:Landroid/view/View;

    invoke-virtual {v0}, Landroid/view/View;->getContext()Landroid/content/Context;

    move-result-object v0

    .line 55
    const-string v1, "window"

    invoke-virtual {v0, v1}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/view/WindowManager;

    .line 54
    iput-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->windowManager:Landroid/view/WindowManager;

    .line 56
    invoke-virtual {p0}, Lcom/noshufou/android/su/widget/BetterPopupWindow;->onCreate()V

    .line 57
    return-void
.end method

.method static synthetic access$0(Lcom/noshufou/android/su/widget/BetterPopupWindow;)Landroid/widget/PopupWindow;
    .locals 1
    .parameter

    .prologue
    .line 26
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    return-object v0
.end method

.method private preShow()V
    .locals 4

    .prologue
    const/4 v3, -0x2

    const/4 v2, 0x1

    .line 71
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->root:Landroid/view/View;

    if-nez v0, :cond_0

    .line 72
    new-instance v0, Ljava/lang/IllegalStateException;

    const-string v1, "setContentView was not called with a view to display."

    invoke-direct {v0, v1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 74
    :cond_0
    invoke-virtual {p0}, Lcom/noshufou/android/su/widget/BetterPopupWindow;->onShow()V

    .line 76
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->background:Landroid/graphics/drawable/Drawable;

    if-nez v0, :cond_1

    .line 77
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    new-instance v1, Landroid/graphics/drawable/BitmapDrawable;

    invoke-direct {v1}, Landroid/graphics/drawable/BitmapDrawable;-><init>()V

    invoke-virtual {v0, v1}, Landroid/widget/PopupWindow;->setBackgroundDrawable(Landroid/graphics/drawable/Drawable;)V

    .line 85
    :goto_0
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    invoke-virtual {v0, v3}, Landroid/widget/PopupWindow;->setWidth(I)V

    .line 86
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    invoke-virtual {v0, v3}, Landroid/widget/PopupWindow;->setHeight(I)V

    .line 87
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    invoke-virtual {v0, v2}, Landroid/widget/PopupWindow;->setTouchable(Z)V

    .line 88
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    invoke-virtual {v0, v2}, Landroid/widget/PopupWindow;->setFocusable(Z)V

    .line 89
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    invoke-virtual {v0, v2}, Landroid/widget/PopupWindow;->setOutsideTouchable(Z)V

    .line 91
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    iget-object v1, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->root:Landroid/view/View;

    invoke-virtual {v0, v1}, Landroid/widget/PopupWindow;->setContentView(Landroid/view/View;)V

    .line 92
    return-void

    .line 79
    :cond_1
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    iget-object v1, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->background:Landroid/graphics/drawable/Drawable;

    invoke-virtual {v0, v1}, Landroid/widget/PopupWindow;->setBackgroundDrawable(Landroid/graphics/drawable/Drawable;)V

    goto :goto_0
.end method


# virtual methods
.method public dismiss()V
    .locals 1

    .prologue
    .line 167
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    invoke-virtual {v0}, Landroid/widget/PopupWindow;->dismiss()V

    .line 168
    return-void
.end method

.method protected onCreate()V
    .locals 0

    .prologue
    .line 63
    return-void
.end method

.method protected onShow()V
    .locals 0

    .prologue
    .line 68
    return-void
.end method

.method public setBackgroundDrawable(Landroid/graphics/drawable/Drawable;)V
    .locals 0
    .parameter "background"

    .prologue
    .line 95
    iput-object p1, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->background:Landroid/graphics/drawable/Drawable;

    .line 96
    return-void
.end method

.method public setContentView(I)V
    .locals 3
    .parameter "layoutResID"

    .prologue
    .line 116
    iget-object v1, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->anchor:Landroid/view/View;

    invoke-virtual {v1}, Landroid/view/View;->getContext()Landroid/content/Context;

    move-result-object v1

    const-string v2, "layout_inflater"

    invoke-virtual {v1, v2}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/view/LayoutInflater;

    .line 117
    .local v0, inflator:Landroid/view/LayoutInflater;
    const/4 v1, 0x0

    invoke-virtual {v0, p1, v1}, Landroid/view/LayoutInflater;->inflate(ILandroid/view/ViewGroup;)Landroid/view/View;

    move-result-object v1

    invoke-virtual {p0, v1}, Lcom/noshufou/android/su/widget/BetterPopupWindow;->setContentView(Landroid/view/View;)V

    .line 118
    return-void
.end method

.method public setContentView(Landroid/view/View;)V
    .locals 1
    .parameter "root"

    .prologue
    .line 105
    iput-object p1, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->root:Landroid/view/View;

    .line 106
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    invoke-virtual {v0, p1}, Landroid/widget/PopupWindow;->setContentView(Landroid/view/View;)V

    .line 107
    return-void
.end method

.method public setOnDismissListener(Landroid/widget/PopupWindow$OnDismissListener;)V
    .locals 1
    .parameter "listener"

    .prologue
    .line 126
    iget-object v0, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    invoke-virtual {v0, p1}, Landroid/widget/PopupWindow;->setOnDismissListener(Landroid/widget/PopupWindow$OnDismissListener;)V

    .line 127
    return-void
.end method

.method public show()V
    .locals 15

    .prologue
    const/4 v12, 0x1

    const/4 v14, -0x2

    const/4 v13, 0x0

    .line 130
    invoke-direct {p0}, Lcom/noshufou/android/su/widget/BetterPopupWindow;->preShow()V

    .line 132
    iget-object v8, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    const v9, 0x7f0d0017

    invoke-virtual {v8, v9}, Landroid/widget/PopupWindow;->setAnimationStyle(I)V

    .line 134
    const/4 v8, 0x2

    new-array v1, v8, [I

    .line 135
    .local v1, location:[I
    iget-object v8, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->anchor:Landroid/view/View;

    invoke-virtual {v8, v1}, Landroid/view/View;->getLocationOnScreen([I)V

    .line 138
    new-instance v0, Landroid/graphics/Rect;

    aget v8, v1, v13

    aget v9, v1, v12

    .line 139
    aget v10, v1, v13

    iget-object v11, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->anchor:Landroid/view/View;

    invoke-virtual {v11}, Landroid/view/View;->getWidth()I

    move-result v11

    add-int/2addr v10, v11

    .line 140
    aget v11, v1, v12

    iget-object v12, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->anchor:Landroid/view/View;

    invoke-virtual {v12}, Landroid/view/View;->getHeight()I

    move-result v12

    add-int/2addr v11, v12

    .line 138
    invoke-direct {v0, v8, v9, v10, v11}, Landroid/graphics/Rect;-><init>(IIII)V

    .line 142
    .local v0, anchorRect:Landroid/graphics/Rect;
    iget-object v8, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->root:Landroid/view/View;

    invoke-virtual {v8, v14, v14}, Landroid/view/View;->measure(II)V

    .line 143
    iget-object v8, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->root:Landroid/view/View;

    invoke-virtual {v8}, Landroid/view/View;->getMeasuredWidth()I

    move-result v3

    .line 144
    .local v3, rootWidth:I
    iget-object v8, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->root:Landroid/view/View;

    invoke-virtual {v8}, Landroid/view/View;->getMeasuredHeight()I

    move-result v2

    .line 146
    .local v2, rootHeight:I
    iget-object v8, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->windowManager:Landroid/view/WindowManager;

    invoke-interface {v8}, Landroid/view/WindowManager;->getDefaultDisplay()Landroid/view/Display;

    move-result-object v8

    invoke-virtual {v8}, Landroid/view/Display;->getWidth()I

    move-result v5

    .line 147
    .local v5, screenWidth:I
    iget-object v8, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->windowManager:Landroid/view/WindowManager;

    invoke-interface {v8}, Landroid/view/WindowManager;->getDefaultDisplay()Landroid/view/Display;

    move-result-object v8

    invoke-virtual {v8}, Landroid/view/Display;->getHeight()I

    move-result v4

    .line 149
    .local v4, screenHeight:I
    iget v6, v0, Landroid/graphics/Rect;->left:I

    .line 150
    .local v6, xPos:I
    iget v7, v0, Landroid/graphics/Rect;->bottom:I

    .line 153
    .local v7, yPos:I
    add-int v8, v7, v2

    if-le v8, v4, :cond_0

    .line 154
    iget-object v8, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    const v9, 0x7f0d0016

    invoke-virtual {v8, v9}, Landroid/widget/PopupWindow;->setAnimationStyle(I)V

    .line 155
    iget v8, v0, Landroid/graphics/Rect;->top:I

    sub-int v7, v8, v2

    .line 159
    :cond_0
    add-int v8, v6, v3

    if-le v8, v5, :cond_1

    .line 160
    iget v8, v0, Landroid/graphics/Rect;->left:I

    iget v9, v0, Landroid/graphics/Rect;->left:I

    add-int/2addr v9, v3

    sub-int/2addr v9, v5

    sub-int v6, v8, v9

    .line 163
    :cond_1
    iget-object v8, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->window:Landroid/widget/PopupWindow;

    iget-object v9, p0, Lcom/noshufou/android/su/widget/BetterPopupWindow;->anchor:Landroid/view/View;

    invoke-virtual {v8, v9, v13, v6, v7}, Landroid/widget/PopupWindow;->showAtLocation(Landroid/view/View;III)V

    .line 164
    return-void
.end method
